<?php
namespace App\Service\OrderService\OrderNotifyService;

use Hyperf\Task\Annotation\Task;
use App\Service\Code\Normal;

class GuiyangNotifyService extends BaseNotifyService
{
    protected $user_type    = 'shopguiyang';
    protected $message_type = 'OrderExpress';

    /**
     * @Task
     * 接收你他云通知物流轨迹
     * @param array $param
     */
    public function orderTraceLogistics( $param = [] )
    {
        $rule = [
            "OrderStatus"       => '订单申报清关状态',
            "OrderNo"           => '渠道商订单号',
            "OrderCode"         => '关务订单号',
            "LogisticsName"     => '物流公司名称',
            "LogisticsNo"       => '物流公司运单号',
            "PayFlowNo"         => '支付流水号',
            "PayCompanyName"    => '支付公司',
            "InvtReleaseTime"   => '清关放行时间',
            "InvtCode"          => '清单放行单号',
            "Message"           => '清关结果',
        ];

        foreach ($rule as $key => $value ) {
            if( !array_key_exists($key,$param) ) {
                return Normal::returnCode(Normal::FAIL,"请求参数【{$key}】缺失");
            }
        }
        $response = $this->getResponseCode();
        $this->response_to_req = $response;
        $this->message = $param;
        $this->event_sn = $param['OrderNo'];
        $this->message_type = 'OrderExpress';
        $this->declare_status = $param['OrderStatus'];
        $result = $this->addNotifyCallBackLog();
        if( $result['code'] != Normal::SUC ) {
            return $result;
        }
        return $response;
    }

    public function goodsReceive($param=[])
    {
        $rule = [
            "datas"              => 'date数据',
        ];

        foreach ($rule as $key => $value ) {
            if( !array_key_exists($key,$param) ) {
                return Normal::returnCode(Normal::FAIL,"请求参数【{$key}】缺失");
            }
        }
        $response = $this->getResponseCode();
        $this->response_to_req = $response;
        $this->message = $param;
        $firstGoods=current($param['datas']);
        $this->event_sn = $firstGoods['goodsSKU'];
        $this->message_type = 'GoodsReceive';
        $result = $this->addNotifyCallBackLog();
        if( $result['code'] != Normal::SUC ) {
            return $result;
        }
        return $response;

    }

    /**
     * 获取接收响应标准
     * 参照当前上游通知业务标准来
     */
    public function getResponseCode()
    {
        return Normal::returnCode(Normal::SUC,"接收成功");
    }
}